package com.junyue.control.platform;

import com.alibaba.fastjson.JSONObject;
import com.junyue.control.platform.entity.ConfigBeanValue;
import com.junyue.control.platform.entity.ResultData;
import com.junyue.control.platform.utils.FileLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 返回手机端版本控制文件
 */
@RestController
@RequestMapping("/ucenter")
public class RouteController {
    @Autowired
    ConfigBeanValue configBeanValue;

    @RequestMapping("/rest.do")
    public String getData(HttpServletRequest request) {
        String packageName = request.getParameter("packageName");
        String appType = request.getParameter("appType");
        String version = request.getParameter("version");
        String key = packageName + "-" + appType + "-" + version;
        Map<String, ResultData> mapData = FileLoader.getInstance(configBeanValue.getFilePath()).getDataMap();
        if (mapData.containsKey(key))
            return JSONObject.toJSONString(mapData.get(key));
        else
            return "";
    }
}
